package controllor

import (
	"fitness/internal/service"
	"fitness/pkg/middleware"
	"github.com/gin-gonic/gin"
)

type DeptController struct {
	DeptService *service.DeptService
	Rbac        *middleware.Rbac
}

func NewDeptController(deptService *service.DeptService, rbac *middleware.Rbac) *DeptController {
	return &DeptController{
		DeptService: deptService,
		Rbac:        rbac,
	}
}

func (api *DeptController) InitApiRouter(engine *gin.Engine) {
	Deptv1 := engine.Group("/dept")
	{
		//获取部门列表
		Deptv1.GET("", middleware.Jwt, api.DeptService.GetDepts)
		//获取部门
		Deptv1.GET("/options", middleware.Jwt, api.DeptService.DeptOptions)
		//查找
		Deptv1.GET("/:deptId/form", middleware.Jwt, api.DeptService.GetDeptForm)
		//新建
		Deptv1.POST("", middleware.Jwt, api.Rbac.RbacAuth("sys:dept:add"), api.DeptService.SaveDept)
		//编辑
		Deptv1.PUT("", middleware.Jwt, api.Rbac.RbacAuth("sys:dept:edit"), api.DeptService.UpdateDept)
		//删除
		Deptv1.DELETE("/:ids", middleware.Jwt, api.Rbac.RbacAuth("sys:dept:delete"), api.DeptService.DeleteDepts)
	}
}
